﻿// Utilities/TypeHelper.cs

using System;

namespace DatabaseManager.Utilities
{
    public static class TypeHelper
    {
        /// <summary>
        /// 安全转换为指定类型
        /// </summary>
        public static T SafeCast<T>(this object value)
        {
            if (value == null || value is DBNull)
                return default;

            try
            {
                return (T)Convert.ChangeType(value, typeof(T));
            }
            catch
            {
                return default;
            }
        }

        /// <summary>
        /// 判断对象是否为数字类型
        /// </summary>
        public static bool IsNumericType(this object o)
        {
            return o is byte || o is short || o is int || o is long ||
                   o is float || o is double || o is decimal;
        }
    }
}